package com.springboot2.jpa.dao;

import com.springboot2.jpa.bean.Article;
import com.springboot2.jpa.bean.Author;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface ArticleRepository extends JpaRepository<Article, Long> {

    @Query(value = "select  a from Article a where a.id=?1")
    Article queryAllById(long id);

    @Query(value = "SELECT a.id,a.title,a.author_id,a.content FROM article a",
            countQuery = "SELECT count(*) FROM article a",
            nativeQuery = true)
    Page<Article> findBytitle(long id, Pageable pageable);


    Page<Article> queryArticleByAuthor(String author, Pageable pageable);
}
